﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace DTO
{
    [DataContract]
    public enum FilterAnswerLogAttributes 
    {
        [EnumMember]
        CharacteristicName,
        [EnumMember]
        Person,
        [EnumMember]
        Department,
        [EnumMember]
        User,
        [EnumMember]
        Operation,
        [EnumMember]
        Volume
    }

    [DataContract]
    public enum FilterInputLogAttributes
    {
        [EnumMember]
        User
    }

    [DataContract]
    public enum ConditionTypes
    {
        [EnumMember]
        Equal,
        [EnumMember]
        GreaterThen,
        [EnumMember]
        LessThen,
        [EnumMember]
        GreaterOrEqualThen,
        [EnumMember]
        LessOrEqualThen,
        [EnumMember]
        Contains,
        [EnumMember]
        NotEqual,
        [EnumMember]
        NotContains
    }

    [DataContract]
    public class FilterItem
    {
        /// <summary>
        /// Атрибут, по которому необходимо фильтровать
        /// </summary>
        [DataMember]
        public object SelectedAttibute { get; set; }
        /// <summary>
        /// Оператор сравнения
        /// </summary>
        [DataMember]
        public ConditionTypes ConditionType { get; set; }
        /// <summary>
        /// Строка, введенная пользователем
        /// </summary>
        [DataMember]
        public object Condition { get; set; }

        public T GetSelectedAttibute<T>()
        {
            return (T)SelectedAttibute;
        }

        public double ConditionAsDouble
        {
            get
            {
                double d = 0;
                double.TryParse(this.Condition.ToString(), out d);
                return d;
            }
        }
    }
}
